package com.alex.android;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button btn = (Button)findViewById(R.id.button1);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				EditText numberCmp = (EditText)findViewById(R.id.editText1);
				String phoneNum = numberCmp.getText().toString();
				Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + phoneNum));
				startActivity(intent);
			}
		});
		
		Button msgBtn = (Button)findViewById(R.id.button2);
		msgBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				EditText numberCmp = (EditText)findViewById(R.id.editText1);
				String phoneNum = numberCmp.getText().toString();
				EditText msgCmp = (EditText)findViewById(R.id.editText2);
				String msg = msgCmp.getText().toString();
				SmsManager smsManager = SmsManager.getDefault();
				List<String> texts = smsManager.divideMessage(msg);
				for(String txt : texts){
					smsManager.sendTextMessage(phoneNum, null, txt, null, null);
				}
				Toast.makeText(getApplicationContext(), "测试", Toast.LENGTH_SHORT).show();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
